const app = getApp()
import{getUrl}from "../../utils/url";
let _this;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    kdtype: [{ la: '小件', price: 1 }, { la: '中件', price: 2 }, { la: '大件', price: 3 }],
    flag:0,
    address:'',
    msg:''
  },
  navTo(e) {
    app.com.navTo(e)
  },
  change(e){
    this.setData({
      flag: e.currentTarget.dataset.index
    })
  },
  
submit(e){
    let formId = e.detail.formId
    if(this.data.address == ''){
      wx.showToast({
        title: '请选择地址',
        icon:'none'
      })
    }else{
      wx.showLoading({
        title: '发布中',
        mask:true
      })
        const {address}= e.currentTarget.dataset;//地址
        let index=e.currentTarget.dataset.index;//索引
       let orders={
        addressId:address.id,
        money:this.data.kdtype[index].price,
        userId:wx.getStorageSync('user').id,
        title:'快递代取:'+this.data.kdtype[index].la,
        schoolId:wx.getStorageSync('area').id//学校id
       } 
       
       wx.request({
        url: getUrl()+`/orderS/save`,  //路径
        data:orders,//参数
        success: function(res) {
          console.log(res.data);
          if(res.data!=null&&res.data!=''){
             wx.showToast({
               title: '发布成功!',
             }),
             setTimeout(function () {
                  wx.switchTab({
              url: '../../pages/banzu/banzu',
            })
              //要延时执行的代码
             }, 2000) //延迟时间 这里是1秒
          }else{
           wx.showToast({
             title: '余额不足,请充值',
             icon:'none'
           })
               
          }
        }
        
      })
      
    
    }
    
  },
  wxpay(msg){
    app.com.wxpay(msg)
  },
  msgiput(e){
 this.setData({
   msg:e.detail.value
 })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      address:wx.getStorageSync('address')
    }) 
  },


})